<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自动定位到对应的View文件</title>
</head>
<body>
<form name="myform">
    用户名:<input type="text" name="userName" id="userName"><br/>
    <input type="checkbox" name="hobby" value="听音乐">听音乐
    <input type="checkbox" name="hobby" value="足球">足球
    <input type="checkbox" name="hobby" value="旅游">旅游<br/>
    <input type="button" value="统计结果" onclick="count()">
</form>
<script type="text/javascript">
function count(){
    let userNmae = document.getElementById("userName");
    let hobby = document.getElementsByName("hobby");
    let result = "ID为userName的元素的值为"+userNmae.value+"\n\t个人爱好元素有:"+hobby.length+"个\n\t"+"选中的个人爱好是：";

    for (let i=0; i<hobby.length;i++){
        if (hobby[i].checked){
            result+=hobby[i].value+" ";
        }
    }
    result+="\n\tinput的标签的个数是："+input.length;
    alert(result);
}

</script>

</body>
</html>